package com.cn.springcloudwechat.controller.personalcenter;

import com.alibaba.druid.sql.visitor.functions.Concat;
import com.cn.springcloudwechat.common.ajax.AjaxRes;
import com.cn.springcloudwechat.common.utils.base.Const;
import com.cn.springcloudwechat.controller.vaccine.log.LogInfo;
import com.cn.springcloudwechat.controller.vaccine.log.OperateType;
import com.cn.springcloudwechat.mapper.mapper.YmUserChildMapper;
import com.cn.springcloudwechat.model.YmChildGrowth;
import com.cn.springcloudwechat.service.personalcenter.service.YmChildGrowthService;
import com.cn.springcloudwechat.service.personalcenter.service.YmUserChildService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/web/childGrowth/")
public class ChildGrowthController {

    @Autowired
    YmChildGrowthService ymChildGrowthService;

    @Autowired
    YmUserChildService ymUserChildService;

    /**
     * 新增宝宝成长记录
     * @param ajaxRes
     * @param ymChildGrowth
     * @return
     */
    @RequestMapping("insertYmChildGrowth")
    @LogInfo(operateType = OperateType.INSERT, content = "新增宝宝成长记录")
    public AjaxRes insertYmChildGrowth(AjaxRes ajaxRes, YmChildGrowth ymChildGrowth){
        try{
            Integer result = ymChildGrowthService.insertYmChildGrowth(ymChildGrowth);
            ajaxRes.setSucceed(result, Const.SAVE_SUCCEED);
        }catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return ajaxRes;
    }


    /**
     * 修改宝宝成长记录
     * @param ajaxRes
     * @param ymChildGrowth
     * @return
     */
    @RequestMapping("updateYmChildGrowth")
    @LogInfo(operateType = OperateType.UPDATE, content = "修改宝宝成长记录")
    public AjaxRes updateYmChildGrowth(AjaxRes ajaxRes, YmChildGrowth ymChildGrowth){
        try{
            Integer result = ymChildGrowthService.updateYmChildGrowth(ymChildGrowth);
            ajaxRes.setSucceed(result, Const.SAVE_SUCCEED);
        }catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return ajaxRes;
    }
    /**
     * 获取宝宝成长记录
     * @param ajaxRes
     * @param
     * @return
     */
    @RequestMapping("getYmChildGrowth")
    @LogInfo(operateType = OperateType.QUERY, content = "获取宝宝成长记录")
    public AjaxRes getYmChildGrowth(AjaxRes ajaxRes,Long childId){
        try {
            List<YmChildGrowth> ymChildGrowth = ymChildGrowthService.getYmChildGrowth(childId);
            ajaxRes.setSucceed(ymChildGrowth, Const.DATA_SUCCEED);
        }catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return ajaxRes;
    }

    /**
     * 获取宝宝最新成长记录
     * @return
     */
    @RequestMapping("getNewestYmChildGrowth")
    @LogInfo(operateType = OperateType.QUERY, content = "获取宝宝最新成长记录")
    public AjaxRes getNewestYmChildGrowth(Long childId,AjaxRes ajaxRes){
        try {
            YmChildGrowth ymChildGrowth = ymChildGrowthService.getNewestYmChildGrowth(childId);
            ajaxRes.setSucceed(ymChildGrowth, Const.DATA_SUCCEED);
        }catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return ajaxRes;
    }
}
